/**
 * 
 */
package it.gommonauti.quiz.patente.app;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;

/**
 * 
 * @author Francesco Stallone ( f.stallone73@gmail.com ).
 * 
 * Splash activity.
 *
 */
public class SplashActivity extends BaseActivity {
	
	private static final String DEBUG_TAG= "SplashActivity";	
	
	private ImageView splash;
	 
	protected boolean _active = true;
	protected int _splashTime = 3000; // time to display the splash screen in ms

    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	Log.i(DEBUG_TAG, "onCreate()");
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        splash = (ImageView) this.findViewById(R.drawable.splash);
        
        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    
                    Intent intent = new Intent();
                    //String mPackage = "it.gommonauti.quiz.patente.app";
                    //String mClass = ".QuizPatenteAppActivity";
                    intent.setClass(SplashActivity.this, ChooseExamActivity.class);
                    startActivity(intent);
                    interrupt();
                }
            }
        };
        splashTread.start();
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
    	
    	Log.i(DEBUG_TAG, "onTouchEvent()");
    	
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
    
    @Override
	protected String getDebugTag() {
		return DEBUG_TAG;
	}
    
}